#include "gamewindow3.h"

#include "GameWindow3.h"
#include <QVBoxLayout>
#include <QMessageBox>
#include <QTimer>
#include <QMouseEvent>

GameWindow3::GameWindow3(QWidget *parent) : QWidget(parent), powerValue(100) {
    this->setFixedSize(800, 600);  // 界面大小
    this->setWindowTitle("喷泉之神的愿望屋");

    // 添加喷泉动画
    fountainLabel = new QLabel(this);
    fountainMovie = new QMovie("D:/QtCreator/HeartIslandTest/figures/Party Celebrate Sticker by GENTLE MONSTER.gif");
    fountainLabel->setMovie(fountainMovie);
    fountainLabel->setGeometry(300, 100, 400, 400);
    fountainMovie->start();

    // 小狐狸
    foxLabel = new QLabel(this);
    foxMovie=new QMovie("D:/QtCreator/HeartIslandTest/figures/fox pixel STICKER.gif");
    foxLabel->setGeometry(100, 400, 80, 80);

    foxButton = new QPushButton("🦊 许愿", this);
    foxButton->setGeometry(100, 500, 80, 40);
    connect(foxButton, &QPushButton::clicked, this, &GameWindow3::showWishFox);

    // 小兔子
    rabbitLabel = new QLabel(this);
    rabbitMovie=new QMovie("D:/QtCreator/HeartIslandTest/figures/bunny jumping STICKER.gif");
    rabbitLabel->setGeometry(600, 400, 120, 120);
    rabbitLabel->setMovie(rabbitMovie);
    rabbitMovie->start();

    rabbitButton = new QPushButton("🐰 许愿", this);
    rabbitButton->setGeometry(600, 500, 80, 40);
    connect(rabbitButton, &QPushButton::clicked, this, &GameWindow3::showWishRabbit);

    // 神力进度条
    powerBar = new QProgressBar(this);
    powerBar->setGeometry(50, 50, 200, 20);
    powerBar->setRange(0, 100);
    powerBar->setValue(powerValue);
    powerBar->setStyleSheet("QProgressBar::chunk { background-color: blue; }");

    // 定时器减少神力
    QTimer *timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &GameWindow3::updatePower);
    timer->start(3000);  // 每3秒减少神力
}

GameWindow3::~GameWindow3() {
    delete fountainMovie;
}

// 展示小狐狸的愿望
void GameWindow3::showWishFox() {
    QMessageBox::information(this, "小狐狸的愿望", "🦊 '喷泉之神，我想学会魔术！\n可以帮我画一个符号吗？'");
}

// 展示小兔子的愿望
void GameWindow3::showWishRabbit() {
    QMessageBox::information(this, "小兔子的愿望", "🐰 '喷泉之神，我想找到神奇的胡萝卜！\n可以帮我用水流冲开泥土吗？'");
}

// 画符咒
void GameWindow3::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
    painter.setPen(QPen(Qt::yellow, 3));

    // 这里可以添加手绘符号的逻辑，先画个简单的五角星
    static const QPoint points[5] = {
        QPoint(400, 250), QPoint(420, 300),
        QPoint(350, 270), QPoint(450, 270),
        QPoint(380, 300)
    };
    painter.drawPolygon(points, 5);
}

// 触摸喷泉水面
void GameWindow3::mousePressEvent(QMouseEvent *event) {
    if (fountainLabel->geometry().contains(event->pos())) {
        QMessageBox::information(this, "喷泉反应", "💦 水面波动了一下...");
    }
}

// 更新神力值
void GameWindow3::updatePower() {
    if (powerValue > 0) {
        powerValue -= 5;
        powerBar->setValue(powerValue);
    }
}

void GameWindow3::closeEvent(QCloseEvent *event) {
    emit gameWindow3Closed();
    QWidget::closeEvent(event);
}
